package com.jz.storeroomclass.mapper;

import com.jz.legalpersonclass.model.LegalPersonVo;
import com.jz.planclass.model.PlanClassVo;
import com.jz.reservoirattributesclass.model.ReservoirattributesVo;
import com.jz.stockidentificationclass.model.StockidentificationVo;
import com.jz.storeroomclass.model.Address;
import com.jz.storeroomclass.model.StoreroomSelectVo;
import com.jz.storeroomclass.model.StoreroomVo;
import com.jz.subclass.model.SubClassVo;
import org.apache.ibatis.annotations.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * Created by WISE on 2021/12/26.
 */
@Mapper
public interface StoreroomMapper {


    List<StoreroomVo> queryData(StoreroomSelectVo storeroomSelectVo);

    int queryCount(StoreroomSelectVo storeroomSelectVo);

    @Select("select * from storeroom where code = #{code}")
    StoreroomVo queryByCode(String code);

    @Select("select * from storeroom where name = #{name}")
    StoreroomVo queryByName(String name);

    @Insert("insert into storeroom(name,code,status,remark,createTime,createName,detailAddress,warehouseTagCode)" +
            "values(#{name},#{code},#{status},#{remark},#{createTime},#{createName},#{detailAddress},#{warehouseTagCode})")
    void add(StoreroomVo classVo);

    @Select("select * from storeroom where id = #{id}")
    List<StoreroomVo> queryById(Integer id);

    @Select("select code subCode from subclass where subName = #{subName}")
    StoreroomVo queryBySubName(@NotBlank(message = "备件小类名称不能为空") String subName);

    @Select("select code planCode from planclass where planName = #{planName}")
    StoreroomVo queryByPlanName(@NotBlank(message = "备件小类名称不能为空") String planName);

    @Select("select *  from legalpersonclass where legalPersonName = #{legalPersonName}")
    LegalPersonVo queryByLegalName(@NotBlank(message = "法人名称不能为空") String legalPersonName);

    @Select("select legalPersonCode legalCode,legalPersonName legalName from legalpersonclass where userId = #{userId}")
    List<StoreroomVo> queryByUserId(Integer userId);

    @Select("select * from subclass ")
    List<SubClassVo> queryAll();

    @Select("select * from planclass ")
    List<PlanClassVo> queryAll2();

    @Update("update storeroom set name = #{name},remark = #{remark},detailAddress = #{detailAddress},status = #{status},warehouseTagCode = #{warehouseTagCode},areaName = #{areaName},updateTime = #{updateTime},updateName = #{updateName} where id = #{id}")
    int update(StoreroomVo classVo);

    @Update("update partclass set status = #{status},updateTime = #{updateTime},updateName = #{updateName} where id = #{id}")
    void updateStatus(StoreroomVo classVo);

    @Delete("delete from partlegal where partCode = #{code}")
    void delete(String code);

    @Select("select * from stockidentification")
    List<StockidentificationVo> queryWarehouseTagList();

    @Select("select * from reservoirattributes")
    List<ReservoirattributesVo> queryBusinessAttribute();

    @Select("select * from storeroom")
    List<StoreroomVo> queryWareHouse();

    @Select("select id value,name label from area")
    List<Address> area();

    @Select("select id value,nation label from nation where areaId =#{id}")
    List<Address> nation(Integer id);

    @Select("select id value,province label from province where nationId =#{id}")
    List<Address> province(Integer id);

    @Select("select id value,city label from city where provinceId =#{id}")
    List<Address> city(Integer id);
    @Select("select id value,county label from county where cityId =#{id}")
    List<Address> county(Integer id);
}


